package com.yanqu.road.server.logic.activity.condition.evefeast;

import com.yanqu.road.entity.activity.ActivityConditionInfo;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.task.TaskModule;
import com.yanqu.road.server.logic.activity.BaseActivityData;
import com.yanqu.road.server.logic.activity.condition.BaseActivityCondition;
import com.yanqu.road.server.manger.activity.evefeast.EveFeastMgr;
import com.yanqu.road.utils.property.Property;

import java.math.BigInteger;

public class EveFeastGameEndCondition extends BaseActivityCondition {
    public EveFeastGameEndCondition(ActivityInfo activityInfo, ActivityConditionInfo activityConditionInfo, BaseActivityData baseActivityData) {
        super(activityInfo, activityConditionInfo, baseActivityData);
    }

    @Override
    protected void player_BoardLevelHandle(Object object) {
        if (isCompleted(player)) {
            return;
        }
        Property itemProperty = (Property) object;
        if (EveFeastMgr.isAchieveActive(itemProperty, activityConditionInfo.getParamList().get(0).intValue())) {
            setValue(BigInteger.ONE);
        }
    }

    @Override
    public boolean isCompleted(GamePlayer player) {
        return getValue().compareTo(BigInteger.ONE) >= 0;
    }

    @Override
    public void addTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().addListener(eGamePlayerEventType.EveFeastGameEndAchieve.getValue(), handle);
    }

    @Override
    public void removeTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().removeListener(eGamePlayerEventType.EveFeastGameEndAchieve.getValue(), handle);
    }
}
